package net.hzlj.platform.enterprise.task;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;
import com.zhy.http.okhttp.callback.StringCallback;

import net.hzlj.platform.enterprise.beans.resp.RespBaseBean;
import net.hzlj.platform.enterprise.utils.GsonUtils;

import cn.finalteam.okhttpfinal.BaseHttpRequestCallback;
import cn.finalteam.okhttpfinal.HttpCycleContext;
import cn.finalteam.okhttpfinal.HttpRequest;
import okhttp3.Call;
import okhttp3.Headers;
import okhttp3.Response;

/**
 * @Description: 网络请求
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015-7-28 14:30:55
 */
public class HttpRequestFileUploadTask<T> extends Task {

    private static final String TAG = HttpRequestFileUploadTask.class.getSimpleName();

    public HttpRequestFileUploadTask(TaskListener listener, HttpCycleContext httpCycleContext){
        super(listener,httpCycleContext);
    }

    public HttpRequestFileUploadTask(TaskListener listener, HttpCycleContext httpCycleContext, Class<T> tClass){
        super(listener,httpCycleContext,tClass);
    }


    @Override
    public void execute() {

        postFormBuilder.build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {
                isSuccess = false;
                rspDesc = e.getMessage();
                listener.onTaskResult(HttpRequestFileUploadTask.this);
            }

            @Override
            public void onResponse(String s) {
                RespBaseBean<T> bean = GsonUtils.fromJson(s,clas);
                resData = bean;
                isSuccess = true;
                rspDesc = bean.getRespMsg();
                listener.onTaskResult(HttpRequestFileUploadTask.this);
            }
        });

        /*HttpRequest.post(url,params,new BaseHttpRequestCallback<String>(){

            @Override
            protected void onSuccess(String o) {
                super.onSuccess(o);
                RespBaseBean<T> bean = GsonUtils.fromJson(o,clas);
                resData = bean;
                isSuccess = true;
                rspDesc = bean.getRespMsg();
                listener.onTaskResult(HttpRequestFileUploadTask.this);
            }

            @Override
            public void onResponse(String response, Headers headers) {
            }

            @Override
            public void onFailure(int errorCode, String msg) {
                super.onFailure(errorCode, msg);
                isSuccess = false;
                rspDesc = "服务器异常";
                listener.onTaskResult(HttpRequestFileUploadTask.this);
            }
        });*/

    }

}
